package com.itheima.stock.controller;

import com.itheima.stock.api.StockControllerAPI;
import com.itheima.stock.entity.StockBusiness;
import com.itheima.stock.response.PageResult;
import com.itheima.stock.response.ResponseResult;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author 28188
 */
@RestController
public class StockController implements StockControllerAPI {

    private final StockService stockService;

    public StockController(StockService stockService) {
        this.stockService = stockService;
    }

    /**
     * 获取股票业务数据
     *
     * @return List
     */
    @Override
    public ResponseResult<List<StockBusiness>> getStockBusiness() {
        List<StockBusiness> stockBusiness = stockService.getStockBusiness();
        return ResponseResult.ok(stockBusiness);
    }

    /**
     * 获取国内大盘数据
     *
     * @return List
     */
    @Override
    public ResponseResult<List<InnerMarketVO>> innerIndexAll() {
        return ResponseResult.ok(stockService.innerIndexAll());
    }

    /**
     * 获取板块数据
     *
     * @return List
     */
    @Override
    public ResponseResult<List<SectorAllVO>> sectorAll() {
        return stockService.sectorAllLimit();
    }

    /**
     * 沪深两市个股涨幅分时行情数据查询，以时间顺序和涨幅查询前10条数据
     *
     * @return List
     */
    @Override
    public ResponseResult<List<IncreaseVO>> stockIncreaseLimit() {
        return stockService.stockIncreaseLimit();
    }

    /**
     * 沪深两市个股涨幅分时行情数据查询，分页查询
     *
     * @return List
     */
    @Override
    public ResponseResult<PageResult<IncreaseVO>> stockPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
        return ResponseResult.ok(stockService.stockPage(page, pageSize));
    }

    /**
     * 获取涨跌统计数据
     *
     * @return UpDownCountVO
     */
    @Override
    public ResponseResult<UpDownCountVO<OptionVO>> upDownCount() {
        return ResponseResult.ok(stockService.upDownCount());
    }

    /**
     * 统计国内A股大盘T日和T-1日成交量对比功能
     *
     * @return List
     */
    @Override
    public ResponseResult<TradingVolumeVO<OptionVO>> stockTradeVol4InnerMarket() {
        return ResponseResult.ok(stockService.stockTradeVol4InnerMarket());
    }

    /**
     * 查询当前时间下股票的涨跌幅度区间统计功能
     * 如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询点
     * @return
     */
    @Override
    public ResponseResult<UpDownAreaVO> getStockUpDown() {
        return ResponseResult.ok(stockService.stockUpDownScopeCount());
    }

    /**
     * 功能描述：查询单个个股的分时行情数据，也就是统计指定股票T日每分钟的交易数据；
     *         如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询时间点
     * @param code 股票编码
     * @return
     */
    @Override
    public ResponseResult<List<Stock4MinuteDomain>> stockScreenTimeSharing(@RequestParam("code") String code) {
        return ResponseResult.ok(stockService.stockScreenTimeSharing(code));
    }

    /**
     * 单个个股日K 数据查询 ，可以根据时间区间查询数日的K线数据
     * @param stockCode 股票编码
     */
    @Override
    public ResponseResult<List<Stock4EvrDayDomain>> getDayKLinData(String stockCode) {
        return stockService.stockCreenDkLine(stockCode);
    }
}